package com.mall.order.controller;

import com.mall.common.annotation.IngoreResponseAdvice;
import com.mall.common.response.CommonResponse;
import com.mall.entity.bargain.BgOrder;
import com.mall.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * created with IntelliJ IDEA
 *
 * @author: S
 * @date: 2021/07/20/15:17
 * Other:  秒杀订单控制层
 */
@RestController
@RequestMapping("/Order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 支付成功方法
     * 传入订单id修改状态
     * @param id
     * @return CommonResponse
     */
    @PutMapping("/updateOrderStatus/{id}/{status}")
    public CommonResponse updateOrderStatus(
            @PathVariable("id") Long id,
            @PathVariable("status") String status
    ){
        return orderService.updateOrderStatus(id,status);
    }

    @PostMapping("/createOrder")
    public BgOrder createOrder(@RequestBody BgOrder bgOrder){
        return orderService.insert(bgOrder);
    }


    /**
     * 根据订单id查询订单记录
     * @return BgOrder
     */
    @GetMapping("/findOne")
    @IngoreResponseAdvice
    public BgOrder findOne(
            @RequestParam("id") Long id
    ){
        return orderService.findOne(id);
    }

}
